package com.fitness.front.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.fitness.front.modal.member.entity.Member;
import com.fitness.front.modal.message.entity.Message;
import com.fitness.front.modal.message.vo.MessageVO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface MessageMapper extends BaseMapper<Message> {

    @Select("SELECT * from t_message where `from` = #{from} and `to` = #{to} order by create_time")
    List<MessageVO> messageList(@Param("from") Long from, @Param("to") Long to);

    @Select("SELECT count(1) FROM t_message tm WHERE tm.`to` = #{memberId}  and status = 'NO_READ'")
    Integer e2eMessageNotReadCount(@Param("memberId") Long memberId);

    @Select("select count(1) from t_message tm where tm.`to` = -1")
    Integer groupMessageCount();

    @Select("select count(1) from t_message tm where tm.`to`=-1 AND JSON_CONTAINS(tm.`read_set`,JSON_ARRAY(#{memberId}))")
    Integer groupReadMessageCount(@Param("memberId") Long memberId);

    @Select("select  DISTINCT m.* from t_message tm,t_member m where m.id = tm.`from` and (tm.`to` = #{memberId} or tm.`to` = -1)")
    List<Member> messageMembers(@Param("memberId") Long memberId);
}
